package com.leyou.common.auth.entity;

import lombok.Data;

//这个类是为了线程安全,也就是controller是单例对象,
// userId会跟每个用户登录有关,若后登陆把先登录人覆盖了就出事了
//这里就是让userId存在线程map中跟每个线程绑定
@Data
public class UserHolder {

    private static ThreadLocal<Long> TL = new ThreadLocal<>();

    public static void setUserId(Long id) {
        TL.set(id);
    }

    public static Long getUserId() {
        return TL.get();
    }

    public static void removeUserId(){
        TL.remove();
    }
}
